import axios from 'axios'
// pinia
import {
	useUserStore
} from '@/stores/use.js';


//1.创建axios对象
const service = axios.create()

// 2.请求拦截器
service.interceptors.request.use(config => {
	const userStore = useUserStore();
	let token = userStore.token
	// 如果有token,附加到请求头
	if (token) {
		config.headers['Authorization'] = token
	}
	return config
}, error => {
	Promise.reject(error)
})

//3. 响应拦截器
service.interceptors.response.use(response => {

	//判断code码

	return response.data
}, error => {
	return Promise.reject(error)
})

export default service